﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Printing.DataGridViewPrint;
using System.Drawing;

namespace QLZJFurnitureSCM.WinForm
{
    public class HeaderPrintBlock : PrintBlock
    {
        //float imgHeight = 75;
        float imgHeight = 0;

        Font font = new Font("Tahoma", 9, GraphicsUnit.Point);

        private string content = string.Empty;

        public HeaderPrintBlock(string content)
        {
            this.content = content;
        }

        public override SizeF GetSize(Graphics g, DocumentMetrics metrics)
        {
            return new SizeF(metrics.PrintAbleWidth, imgHeight + 2); //+2 for spacing with document
        }

        public override void Draw(System.Drawing.Graphics g, Dictionary<CodeEnum, String> codes)
        {
            StringFormat format = new StringFormat();
            format.Trimming = StringTrimming.Word;
            format.FormatFlags = StringFormatFlags.NoWrap;
            //format.Alignment = StringAlignment.Far;
            format.Alignment = StringAlignment.Center;

            g.DrawString(
                string.Format(content),
                font,
                new SolidBrush(Color.Black),
                Rectangle,
                format);
            return;
            //改成写字..
            GraphicsUnit units = GraphicsUnit.Pixel;
            RectangleF rec = Properties.Resources.lavender.GetBounds(ref units);

            float scale = imgHeight / rec.Height;
            // as you can see below, we are using the base.Rectangle.property which has been set by GridDrawer Class
            // after it knows The Size of this block.
            g.DrawImage(Properties.Resources.lavender, new RectangleF(Rectangle.X, Rectangle.Y, rec.Width * scale, imgHeight));
        }
    }
}
